package org.ala.tiktools.generator.mybatis.creator.entity;

import freemarker.template.TemplateException;
import org.ala.tiktools.generator.mybatis.config.info.Part;
import org.ala.tiktools.generator.mybatis.creator.AbstractCreator;
import org.ala.tiktools.generator.mybatis.dbinfo.TableInfo;
import org.ala.tiktools.generator.mybatis.tools.Tools;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author ala
 * @date 2024-12-31 11:15
 */
public class EntityCreator extends AbstractCreator {

    /**
     *  生成Entity类
     */
    public EntityInfo create(Part part, TableInfo table) throws IOException, TemplateException {
        Map<String, Object> dataMeta = new HashMap<>();
        EntityInfo e = EntityInfo.build(part, table);
        dataMeta.put("e", e);

        String out = e.getPkg();
        out = this.getOutRootPath() + out.replaceAll("\\.", "/");
        Tools.existsAndMakeDirs(out);
        out = out + "/" + e.getClassName() + ".java";

        output("Entity.ftl", dataMeta, out);

        System.out.println("生成Entity类. path:" + out);
        return e;
    }
}
